package org.swift.commons.xml.vtd;

import com.ximpleware.extended.AutoPilotHuge;
import com.ximpleware.extended.NavExceptionHuge;
import com.ximpleware.extended.XPathEvalExceptionHuge;
import com.ximpleware.extended.XPathParseExceptionHuge;

public class FileAutomaticPilot implements AutomaticPilot {

	private AutoPilotHuge autoPilot;
	
	public FileAutomaticPilot(AutoPilotHuge autoPilot) {
		this.autoPilot = autoPilot;
	}
	
	@Override
	public void declareXPathNameSpace(String key, String value) {
		this.autoPilot.declareXPathNameSpace(key, value);
	}

	@Override
	public int evalXPath() throws XPathEvaluationException, NavigationException {
		try {
			return this.autoPilot.evalXPath();
		} catch (XPathEvalExceptionHuge e) {
			throw new XPathEvaluationException(e);
		} catch (NavExceptionHuge e) {
			throw new NavigationException(e);
		}		
	}

	@Override
	public String evalXPathToString() {
		return this.autoPilot.evalXPathToString();
	}

	@Override
	public void selectXPath(String xpath) throws XPathParserException {
		try {
			this.autoPilot.selectXPath(xpath);
		} catch (XPathParseExceptionHuge e) {
			throw new XPathParserException(e);
		}		
	}

}
